using UnityEngine;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.IO;
// using ICSharpCode.SharpZipLib.Zip;
using System.Net;
//using EvonyExtension;
using Frankfort.Threading.Internal;
using System.Threading;

public class BundleCompleteInfo
{
	public uint crc;
	public int evony;

	public override bool Equals (object obj)
	{
		if(obj == null)
		{
			return false;
		}
		BundleCompleteInfo i = obj as BundleCompleteInfo;
        return i.crc == this.crc && i.evony == this.evony;
	}
}

public class ExistBundleInfo
{
	public string fileName;
	public string hash;
}

public class BundleVersionManager: Singleton<BundleVersionManager>
{
//	private readonly bool enableLog = false;
//	public const string bundleExt = "unity3d";
//	public const string bundleExt2 = "." + bundleExt;
    public const string bundleExt = "";
    public const string bundleExt2 = "" + bundleExt;
    public const string allLocalBundleConfigName = "local_bundle_config.txt";
	public const string configName2 = "version_config";
	public const string configName = configName2 + ".txt";
//	public const string crcConfigName = configName2 + "_crc" + ".txt";
//	public const string completeConfigName = "bundle_complete.txt";
//	public const string bundleConfigFileSuffix = ".info";
	public static readonly string bundlePath = CommonUtil.cachePath + "/bundle";
	public static readonly string downloadPath =CommonUtil.cachePath + "/download";
	private BundleVersionConfig bundleVersionConfig;
//	private BundleCompleteInfo downloadCompleteInfo;
//	private BundleCompleteInfo needDownloadCompleteInfo;
//	private BundleCompleteInfo readyDownloadCompleteInfo;
//	private Dictionary<string, ExistBundleInfo> existBundleMap = new Dictionary<string, ExistBundleInfo>();
//	private bool _init = false;
//    private Dictionary<string, string> localBundleHashMap = new Dictionary<string, string>();
    private Dictionary<string, Dictionary<string, uint>> downloadedBundleHashMap = new Dictionary<string, Dictionary<string, uint>>();
    private Dictionary<string, LocalBundleInfo> localBundleConfig;

    static BundleVersionManager()
    {
        CommonUtil.CreateDir(bundlePath);
    }

//    public BundleVersionManager()
//    {
//        BundleVersionConfig streamingAssetConfig = null;
////        if (Application.platform == RuntimePlatform.Android)
//        {
////            byte[] data = null;
////            bool ret = CompressManager.DecompressZipEntryToData(Application.dataPath, "assets/" + configName, out data);
////            if (ret && data != null)
////            {
////                string str = System.Text.Encoding.ASCII.GetString(data);
////                streamingAssetConfig = JsonConvert.DeserializeObject<BundleVersionConfig>(str);
////            }
//
//            {
//                TextAsset asset = Resources.Load<TextAsset>(configName);
//                if (asset != null)
//                {
//                    streamingAssetConfig = JsonConvert.DeserializeObject<BundleVersionConfig>(asset.text);
//                }
//            }
//
//            {
//                TextAsset asset = Resources.Load<TextAsset>(allLocalBundleConfigName);
//                if (asset != null)
//                {
//                    localBundleConfig = JsonConvert.DeserializeObject<Dictionary<string, LocalBundleInfo>>(asset.text);
//                }
//            }
//        }
////        else
////        {
////            {
////                string path = Application.streamingAssetsPath + "/" + configName;
////                streamingAssetConfig = CommonUtil.ObjectFromJsonFile<BundleVersionConfig>(path);
////            }
////
////            {
////                string path = Application.streamingAssetsPath + "/" + allLocalBundleConfigName;
////                localBundleConfig = CommonUtil.ObjectFromJsonFile<Dictionary<string, LocalBundleInfo>>(path);
////            }
////        }
//
//        ResetDownloadedBundleHashMap();
//
//        string downloadFilePath = bundlePath + "/" + configName;
//        BundleVersionConfig downloadedConfig = CommonUtil.ObjectFromJsonFile<BundleVersionConfig>(downloadFilePath);
//        if (downloadedConfig != null)
//        {
//            if (Version.version_number < downloadedConfig.min_app_version)
//            {
//                downloadedConfig = null;
//                CommonUtil.Delete(downloadFilePath);
//            }
//
//            if (downloadedConfig != null)
//            {
//                if (GetTotalNeedDownloadSize(downloadedConfig, true) > 0)
//                {
//                    downloadedConfig = null;
//                    CommonUtil.Delete(downloadFilePath);
//                }
//            }
//        }
//
//        if (streamingAssetConfig != null && downloadedConfig != null)
//        {
//            this.bundleVersionConfig = streamingAssetConfig.version > downloadedConfig.version ? streamingAssetConfig : downloadedConfig;
//        }
//        else
//        {
//            this.bundleVersionConfig = streamingAssetConfig ?? downloadedConfig;
//        }
//            
//
//    }


    public void Init(System.Action<bool> callback)
    {
        BundleVersionConfig streamingAssetConfig = null;

        Semaphore semaphore = null;
        string configStr = null;
        string localConfigStr = null;
        if (Application.platform == RuntimePlatform.Android && !Application.isEditor)
        {
            semaphore = new Semaphore(0, 2);
//            ResourceManager.LoadAssetAsync(configName, (obj, path) =>
//                {
//                    if (obj != null)
//                    {
//                        TextAsset asset = obj as TextAsset;
//                        configStr = asset.text;
//                    }
//                    semaphore.Release();
//                });
//
//            ResourceManager.LoadAssetAsync(allLocalBundleConfigName, (obj, path) =>
//                {
//                    if (obj != null)
//                    {
//                        TextAsset asset = obj as TextAsset;
//                        localConfigStr = asset.text;
//                    }
//                    semaphore.Release();
//                });

            string configPath = Application.streamingAssetsPath + "/" + configName;
            WwwManager.Load(configPath, (www) =>
                {
                    configStr = www.text;
                    if(configStr == null)
                    {
                        Debug.LogError("load config failed: " + configPath);
                    }
                    semaphore.Release();
                });

            string configPath2 = Application.streamingAssetsPath + "/" + allLocalBundleConfigName;
            WwwManager.Load(configPath2, (www) =>
                {
                    localConfigStr = www.text;
                    if(localConfigStr == null)
                    {
                        Debug.LogError("load config failed: " + configPath2);
                    }
                    semaphore.Release();
                });
        }
        
        string streamingAssetDir = Application.streamingAssetsPath;
        string dataDir = Application.dataPath;
        bool isEditor = Application.isEditor;
        SingleThreadStarter.StartSingleThread(() =>
            {
                string downloadFilePath = bundlePath + "/" + configName;
                BundleVersionConfig downloadedConfig = CommonUtil.ObjectFromJsonFile<BundleVersionConfig>(downloadFilePath);
                if (Application.platform == RuntimePlatform.Android && !isEditor)
                {
//                    {
//                        byte[] data = null;
//                        bool ret = CompressManager.DecompressZipEntryToData(dataDir, "assets/" + configName, out data);
//                        if (ret && data != null)
//                        {
//                            string str = System.Text.Encoding.UTF8.GetString(data);
//                            streamingAssetConfig = JsonConvert.DeserializeObject<BundleVersionConfig>(str);
//                        }
//                    }
//
//                    {
//                        byte[] data = null;
//                        bool ret = CompressManager.DecompressZipEntryToData(dataDir, "assets/" + allLocalBundleConfigName, out data);
//                        if (ret && data != null)
//                        {
//                            string str = System.Text.Encoding.UTF8.GetString(data);
//                            localBundleConfig = JsonConvert.DeserializeObject<Dictionary<string, LocalBundleInfo>>(str);
//                        }
//                    }

                    semaphore.WaitOne();
                    semaphore.WaitOne();
                    if (configStr != null)
                    {
                        streamingAssetConfig = JsonConvert.DeserializeObject<BundleVersionConfig>(configStr);
                    }

                    if (localConfigStr != null)
                    {
                        localBundleConfig = JsonConvert.DeserializeObject<Dictionary<string, LocalBundleInfo>>(localConfigStr);
                    }
                }
                else
                {
                    string path = streamingAssetDir + "/" + configName;
                    streamingAssetConfig = CommonUtil.ObjectFromJsonFile<BundleVersionConfig>(path);
                    string localConfigPath = streamingAssetDir + "/" + allLocalBundleConfigName;
                    localBundleConfig = CommonUtil.ObjectFromJsonFile<Dictionary<string, LocalBundleInfo>>(localConfigPath);
                }

                ResetDownloadedBundleHashMap();

                if (downloadedConfig != null)
                {
                    //only dependence by server, no check min_app_version here
                    // if (VersionEx.version_number < downloadedConfig.min_app_version)
                    // {
                    //     downloadedConfig = null;
                    //     CommonUtil.Delete(downloadFilePath);
                    // }

                    if (downloadedConfig != null)
                    {
                        if (GetTotalNeedDownloadSize(downloadedConfig, true) > 0)
                        {
                            downloadedConfig = null;
                            CommonUtil.Delete(downloadFilePath);
                        }
                    }
                }

                if (streamingAssetConfig != null && downloadedConfig != null)
                {
                    this.bundleVersionConfig = streamingAssetConfig.version > downloadedConfig.version ? streamingAssetConfig : downloadedConfig;
                }
                else
                {
                    this.bundleVersionConfig = streamingAssetConfig ?? downloadedConfig;
                }

                MainThreadDispatcher.DispatchToMainThread(() =>
                    {
                        callback(true);
                    });
            });
    }

    public void ResetDownloadedBundleHashMap()
    {
        downloadedBundleHashMap.Clear();
        if (Directory.Exists(bundlePath))
        {
            DirectoryInfo dirInfo = new DirectoryInfo(bundlePath);
            FileInfo[] fileInfos = dirInfo.GetFiles("*", SearchOption.TopDirectoryOnly);

            for (int i = 0; i < fileInfos.Length; i++)
            {
                FileInfo fileInfo = fileInfos[i];
                string path = fileInfo.FullName;
                if (string.IsNullOrEmpty(fileInfo.Extension))
                {
                    string fileName = fileInfo.Name;
                    string hash = null;
                    string bundleName = BundleInfo.ConvertToBundleNameAndHash(fileName, ref hash);
                    if (bundleName == null)
                    {
                        CommonUtil.Delete(path);
                        continue;
                    }

                    Dictionary<string, uint> hashSet = new Dictionary<string, uint>();
                    if (!downloadedBundleHashMap.TryGetValue(bundleName, out hashSet))
                    {
                        hashSet = new Dictionary<string, uint>();
                        downloadedBundleHashMap.Add(bundleName, hashSet);
                    }
                    hashSet.Add(hash, (uint)fileInfo.Length);
                }
            }
        }
    }

    public LocalBundleInfo isBundleExistInApp(BundleInfo info)
    {
        LocalBundleInfo tempInfo = null;
        if (localBundleConfig != null)
        {
            if (localBundleConfig.TryGetValue(info.name, out tempInfo))
            {
                if (tempInfo.hash == info.hash)
                {
                    return tempInfo;
                }
            }
        }
        return null;
    }

    public bool isBundleExist(BundleInfo info, out LocalBundleInfo localBundleInfo, out bool inApp)
    {
        inApp = false;
        Dictionary<string, uint> temp = null;
        if (downloadedBundleHashMap.TryGetValue(info.name, out temp))
        {
            uint size = 0;
            if (temp.TryGetValue(info.hash, out size))
            {
                if (size == info.size)
                {
                    localBundleInfo = null;
                    return true;
                }
            }
        }

        localBundleInfo = isBundleExistInApp(info);

        inApp = localBundleInfo != null;

        return inApp;
    }

    public string GetBundleFilePath(string bundleName)
    {
        BundleInfo info = null;
        if (!this.bundleVersionConfig.bundles.TryGetValue(bundleName, out info))
        {
            return null;
        }

        LocalBundleInfo localBundleInfo = null;
        bool inApp = false;
        if (!isBundleExist(info, out localBundleInfo, out inApp))
        {
            return null;
        }

        if (localBundleInfo != null)
        {
            return localBundleInfo.GetLocalBundlePath();
        }
        else
        {
            return info.GetDownloadPath();
        }
    }

    public uint GetTotalNeedDownloadSize(BundleVersionConfig config, bool onlyEssential = false)
    {
        if (config == null)
        {
            return 0;
        }

        uint size = 0;
        Dictionary<string, BundleInfo>.Enumerator e = config.bundles.GetEnumerator();
        while (e.MoveNext())
        {
            if (onlyEssential)
            {
                if (localBundleConfig == null)
                {
                    continue;
                }

                LocalBundleInfo tempInfo = null;
                if(!localBundleConfig.TryGetValue(e.Current.Key, out tempInfo))
                {
                    continue;
                }

                if (tempInfo.local_type != LocalType.essential)
                {
                    continue;
                }
            }

            LocalBundleInfo localBundleInfo = null;
            bool inApp = false;
            if (!isBundleExist(e.Current.Value, out localBundleInfo, out inApp))
            {
                size += e.Current.Value.size;
            }
        }

        return size;
    }

    public uint GetTotalNeedDecompressSize(BundleVersionConfig config)
    {
        if (config == null)
        {
            return 0;
        }

        if (localBundleConfig == null)
        {
            return 0;
        }

        if (Application.platform != RuntimePlatform.Android || Application.isEditor)
        {
            return 0;
        }

        uint size = 0;
        Dictionary<string, BundleInfo>.Enumerator e = config.bundles.GetEnumerator();
        while (e.MoveNext())
        {
            LocalBundleInfo tempInfo = null;
            if(!localBundleConfig.TryGetValue(e.Current.Key, out tempInfo))
            {
                continue;
            }

            if (tempInfo.local_type != LocalType.unessential)
            {
                continue;
            }

            LocalBundleInfo localBundleInfo = null;
            bool inApp = false;
            bool exist = isBundleExist(e.Current.Value, out localBundleInfo, out inApp);
            if (!exist || localBundleInfo != null)
            {
                size += e.Current.Value.size;
            }
        }

        return size;
    }

//	public static void createDir()
//	{
//		CommonUtil.CreateDir(bundlePath);
//		CommonUtil.CreateDir(downloadPath);
//	}

//	public static void deleteDir()
//	{
//		CommonUtil.Delete(bundlePath);
//		CommonUtil.Delete(downloadPath);
//	}

//	public void addExistBundle(string bundleName)
//	{
//		BundleInfo info = null;
//		this.bundleVersionConfig.bundles.TryGetValue(bundleName, out info);
//		ExistBundleInfo info2 = new ExistBundleInfo();
//        info2.hash = info.hash;
//        info2.fileName = info.GetHashName();
//		existBundleMap.Add(bundleName, info2);
//	}

//	public void initExistBundleInfo()
//	{
//		if(!Directory.Exists(BundleVersionManager.bundlePath))
//		{
//			return;
//		}
//
//		this.existBundleMap.Clear();
//
//		{
//			string[] paths = Directory.GetFiles(BundleVersionManager.bundlePath, "*" + ".info", SearchOption.AllDirectories);
//			for(int i = 0; i < paths.Length; i++)
//			{
//				string configPath = paths[i];
//				try
//				{
//					BundleInfo info = JsonConvert.DeserializeObject<BundleInfo> (CommonUtil.fileToString(configPath));
//					string bundleName = Path.GetFileNameWithoutExtension(configPath);
//					string bundlePath = Path.GetDirectoryName(configPath) + "/" + bundleName + BundleVersionManager.bundleExt2;
//                    string destPath = Path.GetDirectoryName(configPath) + "/" + info.GetHashName() + BundleVersionManager.bundleExt2;
//					CommonUtil.Move(bundlePath, destPath);
//					CommonUtil.Delete(configPath);
//				}
//				catch(System.Exception e)
//				{
//					if(Debug.enableLog) Debug.LogWarning(e);
//				}
//			}
//		}
//
//		{
//			string[] paths = Directory.GetFiles(BundleVersionManager.bundlePath, "*" + BundleVersionManager.bundleExt2, SearchOption.AllDirectories);
//			for(int i = 0; i < paths.Length; i++)
//			{
//				string bundleFilePath = paths[i];
//				string fileName = Path.GetFileNameWithoutExtension(bundleFilePath);
//                string hash = null;
//                string bundleName = BundleInfo.ConvertToBundleNameAndHash(fileName, ref hash);
//				if(bundleName != null)
//				{
//					string bundlePath2 = bundlePath +"/" + fileName + BundleVersionManager.bundleExt2;
//					uint fileSize = (uint)CommonUtil.GetFileSize(bundlePath2);
//					BundleInfo info = null;
//					if(this.GetBundleVersionConfig().bundles.TryGetValue(bundleName, out info))
//					{
//						if(info.origin_size == fileSize)
//						{
//							ExistBundleInfo info2 = new ExistBundleInfo();
//                            info2.hash = hash;
//							info2.fileName = fileName;
//							this.existBundleMap.Add(bundleName, info2);
//						}
//						else
//						{
//							CommonUtil.Delete(bundlePath2);
//						}
//					}
//					else
//					{
//						CommonUtil.Delete(bundlePath2);
//					}
//				}
//			}
//		}
//	}

	public void DelOldBundles()
	{
        if (this.bundleVersionConfig == null)
        {
            return;
        }

        HashSet<string> deleteBundles = new HashSet<string>();
        Dictionary<string, Dictionary<string, uint>>.Enumerator e = this.downloadedBundleHashMap.GetEnumerator();
        while (e.MoveNext())
        {
            BundleInfo info = null;
            this.bundleVersionConfig.bundles.TryGetValue(e.Current.Key, out info);


            HashSet<string> deleteHashs = new HashSet<string>();

            Dictionary<string, uint>.KeyCollection keys = e.Current.Value.Keys;
            foreach(var key in keys)
            {
                if (info == null || info.hash != key)
                {
                    string fileName = BundleInfo.GetHashName(e.Current.Key, key);
                    string filePath = bundlePath + "/" + fileName;
                    CommonUtil.Delete(filePath);

                    if (info != null)
                    {
                        deleteHashs.Add(key);
                    }
                }
            }

            foreach (var hash in deleteHashs)
            {
                e.Current.Value.Remove(hash);
            }

            if (info == null)
            {
                deleteBundles.Add(e.Current.Key);
            }
        }

        foreach (var bundleName in deleteBundles)
        {
            this.downloadedBundleHashMap.Remove(bundleName);
        }
	}

//	public ExistBundleInfo getExistBundleInfo(string bundleName)
//	{
//		ExistBundleInfo info = null;
//		existBundleMap.TryGetValue(bundleName, out info);
//		return info;
//	}

//	void initLocalConfig ()
//	{
//		//		if(!SwitchConfig.isEnableDownloadBundle)
//		//		{
//		//			return;
//		//		}
//		
//		if(bundleVersionConfig == null)
//		{
//			string configContent = CommonUtil.fileToString (bundlePath + "/" + configName);
//			if (configContent != null)
//			{
//				bundleVersionConfig = BundleDownloadManager.ConvertToBundleVersionConfig(configContent);
//			}
//		}
//
//		if(downloadCompleteInfo == null)
//		{
//			string configContent = CommonUtil.fileToString (bundlePath + "/" + completeConfigName);
//			if (configContent != null)
//			{
//				downloadCompleteInfo = BundleDownloadManager.ConvertToCompleteInfo(configContent);
//			}
//		}
//	}

//	public void setReadyBundleCompleteInfo(BundleCompleteInfo info)
//	{
//		this.readyDownloadCompleteInfo = info;
//		if(downloadCompleteInfo != null && !downloadCompleteInfo.Equals(readyDownloadCompleteInfo))
//		{
//			downloadCompleteInfo = null;
//			CommonUtil.Delete(bundlePath + "/" + completeConfigName);
//		}
//	}
//
//	public bool needDownload()
//	{
//		return downloadCompleteInfo == null || !downloadCompleteInfo.Equals(readyDownloadCompleteInfo);
//	}
//
//	public void completeDownload()
//	{
//		if(needDownload() && readyDownloadCompleteInfo != null)
//		{
//			this.downloadCompleteInfo = readyDownloadCompleteInfo;
//			readyDownloadCompleteInfo = null;
//			string s = JsonConvert.SerializeObject(downloadCompleteInfo);
//			CommonUtil.stringToFile(bundlePath + "/" + completeConfigName, s);
//		}
//	}
//
//	public void Init()
//	{
//		if (!_init)
//		{
//			_init = true;
//			initLocalConfig ();
//		}
//	}
	
	public string GetBundleConfigMd5()
	{
		if(bundleVersionConfig != null)
		{
            return bundleVersionConfig.md5;
		}

        return null;
//
////		uint crc = 0;
//		string str = CommonUtil.fileToString(BundleVersionManager.bundlePath + "/" + BundleVersionManager.crcConfigName);
//        return str;

//		initLocalConfig ();
//		
//		if (bundleVersionConfig != null)
//		{
//			return bundleVersionConfig.crc;
//		}
		
//		return 0;
	}
	
	public BundleVersionConfig GetBundleVersionConfig()
	{
		return this.bundleVersionConfig;
	}

    public int GetVersion()
    {
        if (this.bundleVersionConfig != null)
        {
            return this.bundleVersionConfig.version;
        }
        return 0;
    }

    public int GetMinAppVersion()
    {
        if (this.bundleVersionConfig != null)
        {
            return this.bundleVersionConfig.min_app_version;
        }
        return 0;
    }
	

    public BundleVersionConfig GetLatestConfig(BundleVersionConfig config)
    {
        if (config == null)
        {
            return this.bundleVersionConfig;
        }

        if (this.bundleVersionConfig != null)
        {
            if (this.bundleVersionConfig.version == config.version && this.bundleVersionConfig.md5 == config.md5)
            {
                return this.bundleVersionConfig;
            }

            if (this.bundleVersionConfig.version > config.version)
            {
                return this.bundleVersionConfig;
            }
        }

        return config;
    }

	public void SetBundleVersionConfig(BundleVersionConfig config)
	{
        if (config == null)
        {
            return;
        }

        config = GetLatestConfig(config);
        if (!config.Equals(this.bundleVersionConfig))
        {
			string downloadFilePath = bundlePath + "/" + configName;
			CommonUtil.ObjectToJsonFile(config, downloadFilePath);
			this.bundleVersionConfig = config;
        }
	}
//	
//	public uint getNeedDownloadSizeOfBundles(BundleVersionConfig newConfig)
//	{
//		return getNeedDownloadSizeOfBundles(newConfig, bundleVersionConfig);
//	}
//	
//	private static uint getNeedDownloadSizeOfBundles(BundleVersionConfig newConfig, BundleVersionConfig oldConfig)
//	{
//		if(newConfig == null)
//		{
//			return 0;
//		}
//		
//		if(oldConfig == null)
//		{
//			return newConfig.size;
//		}
//		
//		uint sizeSum = 0;
//		Dictionary<string, BundleInfo>.Enumerator enumerator = newConfig.bundles.GetEnumerator();
//		while(enumerator.MoveNext())
//		{
//			string bundleName = enumerator.Current.Key;
//			BundleInfo newBundleInfo = enumerator.Current.Value;
//			BundleInfo oldBundleInfo = null;
//			if(oldConfig.bundles.TryGetValue(bundleName, out oldBundleInfo))
//			{
//                if(oldBundleInfo.hash != newBundleInfo.hash)
//				{
//					sizeSum += newBundleInfo.size;
//				}
//			}
//			else
//			{
//				sizeSum += newBundleInfo.size;
//			}
//		}
//		
//		return sizeSum;
//	}
//	
//	public bool isNeedUpdate(BundleVersionConfig newConfig)
//	{
//		return isNeedUpdate(newConfig, this.bundleVersionConfig);
//	}
//	
//	public static bool isNeedUpdate(BundleVersionConfig newConfig, BundleVersionConfig oldConfig)
//	{
////		if (!SwitchConfig.isEnableDownloadBundle)
////		{
////			return false;
////		}
//		
//		if(newConfig == null)
//		{
//			return false;
//		}
//		
//		if(oldConfig == null)
//		{
//			return true;
//		}
//
//		if(oldConfig.min_app_version > Version.version_number)
//		{
//			return true;
//		}
//
//        if(newConfig.md5 == oldConfig.md5)
//		{
//			return false;
//		}
//
//		if(newConfig.version == oldConfig.version)
//		{
//			System.DateTime newTime = new System.DateTime();
//			if(System.DateTime.TryParse(newConfig.build_time, out newTime))
//			{
//				System.DateTime oldTime = new System.DateTime();
//				if(System.DateTime.TryParse(oldConfig.build_time, out oldTime))
//				{
//					int result = System.DateTime.Compare(newTime, oldTime);
//					if(result > 0)
//					{
//						return true;
//					}
//					else
//					{
//						return false;
//					}
//				}
//			}
//		}
//
//		return true;
//	}
//	
//	public int compareLocalVersion(string bundleName, BundleInfo localConfigBundleInfo)
//	{
//		ExistBundleInfo info = BundleVersionManager.instance.getExistBundleInfo(bundleName);
//		if(info != null)
//		{
//            if(info.hash != localConfigBundleInfo.hash)
//			{
//
//			}
//			else
//			{
//				return 0;
//			}
//		}
//		
//		return 1;
//	}
}